package com.jacksay.vikingfl.autocompleter
{
	import mx.containers.Canvas;
	import mx.controls.Label;
	import mx.controls.listClasses.BaseListData;
	import mx.controls.listClasses.IDropInListItemRenderer;
	import mx.core.IFactory;
	import mx.core.ScrollPolicy;

	public class AutoCompleterRemoteCompletionRenderer extends Canvas implements IFactory, IDropInListItemRenderer
	{
		
		/**
		 * @protected
		 */
		protected var labelField:Label = new Label();
		
		public function AutoCompleterRemoteCompletionRenderer()
		{
			super();
			setStyle("verticalAlign","middle");
			// labelField.percentWidth = 100;
			clipContent = true;
			setStyle("horizontalGap",1);
			labelField.truncateToFit = true;
			labelField.percentWidth = 100;
			verticalScrollPolicy = ScrollPolicy.OFF;
			horizontalScrollPolicy = ScrollPolicy.OFF;
			addChild(labelField);
		}
		
		public override function set data( value:Object ) :void {
			super.data = value;
		}
		
		private var _listData:BaseListData;
		
		public function get listData():BaseListData
        {
        	return _listData;
        }
		
        public function set listData( value:BaseListData ):void
        {
        	_listData = value;
        	if( _listData == null ) return;
        	
        	refreshDisplay();
        } 
        
        protected function refreshDisplay() :void {
        	// on supprime l'occupation de la scrollbar
        	width = listData.owner.width - 22;
        	labelField.htmlText = listData.label;
        }
		
		public function newInstance()
		{
			return new AutoCompleterRemoteCompletionRenderer();
		}
		
		public function set text(value:String):void {
			labelField.htmlText = value;
		}
		
		public function get text() :String {
			return labelField.htmlText;
		}
		
	}
}